Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

434
Visualizações
Randomly get Error SQLSTATE[HY000] [14] unable to open database file - PHP PDO

This error appears randomly. I'm able to write and read the database file, but sometimes doesn't work, even with the same request.

I tried to test just one connection (to avoid multiple, thinking that could be the problem), and also randomly fails.

I checked the permissions of the file(windows), and all in order (if not I wouldn't be able to write the file)

This is the code to connect to database:

class Con{

    private $pdo;

    public function conex($db){

        try{

            // $pdo = $this->pdo;

            if ($this->pdo == null){

                sleep(0.1);
                $this->pdo = new PDO("sqlite:../../content/engine/" . $db,"","",array(
                    PDO::ATTR_PERSISTENT => true
                ));

                $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);      

            } 

            return $this->pdo;


        }catch(PDOException $e){

            die( $e->getMessage());

        } finally{

            $this->pdo = null;

        }
    }
}

class Q_General extends Con{

    protected $db;

    public function __construct($db){

        if ($this->db == null){

            $this->db = $this->conex($db);
        }
        
    } 

    public function get_query($sql){

        $query = $this->db->prepare($sql);
        $query->execute();

        $res = $query->fetchAll();
        $query->closeCursor();

        return $res;

    }
}

I do the request with ajax, so I can control the number and order of request and setup a queue for every request with the purpose of avoid write or read at the same time.

Any clue what can I be doing wrong?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda